package arm.attestation.bean;

import javax.swing.text.NumberFormatter;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class PostMetric
{
    private Integer keyWorkplace;
    private Integer numberWorkplace;
    private String dicPostName;
    private String dicMetricTypeName;
    private Double value;
    private Double maxDimension;
    private Double minDimension;

    public PostMetric(Integer keyWorkplace, Integer number_workplace, String dicPostName, String dicMetricTypeName, Double value, Double maxDimension, Double minDimension) {
        this.keyWorkplace = keyWorkplace;
        this.numberWorkplace = number_workplace;
        this.dicPostName = dicPostName;
        this.dicMetricTypeName = dicMetricTypeName;
        this.value = value;
        this.maxDimension = maxDimension;
        this.minDimension = minDimension;
    }

    public Integer getKeyWorkplace() {
        return keyWorkplace;
    }

    public void setKeyWorkplace(Integer keyWorkplace) {
        this.keyWorkplace = keyWorkplace;
    }

    public Integer getNumberWorkplace() {
        return numberWorkplace;
    }

    public void setNumberWorkplace(Integer numberWorkplace) {
        this.numberWorkplace = numberWorkplace;
    }

    public String getDicPostName() {
        return dicPostName;
    }

    public void setDicPostName(String dicPostName) {
        this.dicPostName = dicPostName;
    }

    public String getDicMetricTypeName() {
        return dicMetricTypeName;
    }

    public void setDicMetricTypeName(String dicMetricTypeName) {
        this.dicMetricTypeName = dicMetricTypeName;
    }

    public Double getValue() {
        return value;
    }

    public void setValue(Double value) {
        this.value = value;
    }

    public Double getMaxDimension() {
        return maxDimension;
    }

    public void setMaxDimension(Double maxDimension) {
        this.maxDimension = maxDimension;
    }

    public Double getMinDimension() {
        return minDimension;
    }

    public void setMinDimension(Double minDimension) {
        this.minDimension = minDimension;
    }

    public String getNormiTxt()
    {
        String result = "-";
        NumberFormat formatter = new DecimalFormat("#0.00");
        if (getMinDimension() == null || getMinDimension() == 0)
            result = (getMaxDimension() != null && getMaxDimension() != 0)
                    ? "<=" + formatter.format(getMaxDimension())
                    :"-";
        else
            result = (getMaxDimension() != null && getMaxDimension() != 0)
                    ? formatter.format(getMinDimension()) +"-" + formatter.format(getMaxDimension())
                    : ">=" + formatter.format(getMinDimension());
        return result;
    }

    public String getResult()
    {
        String result = "-";
        NumberFormat formatter = new DecimalFormat("#0.00");
        if ((getMinDimension() == null || getMinDimension() == 0)
                && (getMaxDimension() != null && getMaxDimension() != 0))
            result = formatter.format(getValue() - getMaxDimension());
        if ((getMinDimension() != null && getMinDimension() != 0)
                && (getMaxDimension() != null && getMaxDimension() != 0))
            result =  getBetweenResult(getMinDimension(),getMaxDimension(), getValue());
        if ((getMaxDimension() == null || getMaxDimension() == 0)
                && (getMinDimension() != null && getMinDimension() != 0))
            result = formatter.format(getMinDimension() - getValue());

        return result;
    }

    private String getBetweenResult(Double minDimension, Double maxDimension, Double value) {
        NumberFormat formatter = new DecimalFormat("#0.00");
        if ((value >= minDimension) && (value <= maxDimension))
            return "-";
        if (value < minDimension)
            return formatter.format(value - minDimension);
        if (value > maxDimension)
            return formatter.format(maxDimension - value);
        return "-";
    }
}